package com.jmu.bishe.utils;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;


/**
 *<pre><b><font color="blue">ArrUtils</font></b></pre>
 *<pre><b>&nbsp;--数组工具类--</b></pre>
 * JDK版本：JDK1.5.0
 * @author  <b></b> 
 */
public class ArrUtils {
	
	/** 以某个字符串域字段排序List
	 * @param list
	 * @param field
	 * @return 
	 * @author: ulyn
	 */
	public static void sortByStringField(List list,final String field) {
		Collections.sort(list, new Comparator() {
		      @Override
		      public int compare(Object o1, Object o2) {
		    	  String s1 = (String)((Map)o1).get(field);
		    	  String s2 = (String)((Map)o2).get(field);
		    	  return s1.compareTo(s2);
		      }
		});
	}
    /** 以某个字符串域字段倒序排序List
     * @param list
     * @param field
     * @return
     * @author: ulyn
     */
    public static void sortDescByStringField(List list,final String field) {
        Collections.sort(list, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                String s1 = (String)((Map)o1).get(field);
                String s2 = (String)((Map)o2).get(field);
                return s2.compareTo(s1);
            }
        });
    }
	/** 以某个int域字段排序List
	 * @param list
	 * @param field
	 * @return 
	 * @author: ulyn
	 */
	public static void sortByIntField(List list,final String field) {
		Collections.sort(list, new Comparator() {
		      @Override
		      public int compare(Object o1, Object o2) {
		    	  String s1 = ((Map)o1).get(field).toString();
		    	  String s2 = ((Map)o2).get(field).toString();
		    	  return new Integer(s1).compareTo(new Integer(s2));
		      }
		});
	}
    /** 以某个int域字段倒序排序List
     * @param list
     * @param field
     * @return
     * @author: ulyn
     */
    public static void sortDescByIntField(List list,final String field) {
        Collections.sort(list, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                String s1 = ((Map)o1).get(field).toString();
                String s2 = ((Map)o2).get(field).toString();
                return new Integer(s2).compareTo(new Integer(s1));
            }
        });
    }
}
